#ifndef _IHTTP_H_
#define _IHTTP_H_

typedef enum {
    HTTP_IMPL_UNKNOWN = 0,

    HTTP_IMPL_CONNECT_FAIL,
    HTTP_IMPL_CONNECTING,
    HTTP_IMPL_CONNECTED,

    HTTP_IMPL_LOCATION_FAIL,
    HTTP_IMPL_LOCATION,
    HTTP_IMPL_LOCATIONED,

    HTTP_IMPL_SEND_HEAD_FAIL,
    HTTP_IMPL_SEND_HEAD,
    HTTP_IMPL_SEND_HEADED,

    HTTP_IMPL_SEND_BODY_FAIL,
    HTTP_IMPL_SEND_BODY,
    HTTP_IMPL_SEND_BODYED,

    HTTP_IMPL_RECV_HEAD_FAIL,
    HTTP_IMPL_RECV_HEAD,
    HTTP_IMPL_RECV_HEADED,

    HTTP_IMPL_RECV_BODY_FAIL,
    HTTP_IMPL_RECV_BODY,
    HTTP_IMPL_RECV_BODYED,

    HTTP_IMPL_END

} http_state_t;

typedef enum {
    HTTP_METHOD_UNKNOWN,
    HTTP_METHOD_GET,
    HTTP_METHOD_POST,
    HTTP_METHOD_PUT,
    HTTP_METHOD_CONNECT,
    HTTP_METHOD_PURGE,
    HTTP_METHOD_DELETE,
    HTTP_METHOD_HEAD,
    HTTP_METHOD_OPTION,
    HTTP_METHOD_PROPFIND,
    HTTP_METHOD_OTHER,
} http_method_t;

typedef enum {
    // Content-Type: application/x-www-form-urlencoded
    HTTP_REQUEST_NORMAL,

    // Content-Type: multipart/form-data; boundary=xxx
    HTTP_REQUEST_MULTIPART_FORM,

    // Content-Type: application/octet-stream
    HTTP_REQUEST_OCTET_STREAM,

    // Content-Type: text/xml
    HTTP_REQUEST_TEXT_XML,

    // Content-Type: text/json
    HTTP_REQUEST_TEXT_JSON,

    //
    HTTP_REQUEST_OTHER
} http_request_t;

typedef enum {
    HTTP_MIME_PARAM, // http mime param
    HTTP_MIME_FILE   // http mime file
} http_mime_t;

typedef unsigned long http_data_len;
typedef const char* http_addr_s;
typedef const char* http_header;
typedef const char* http_method_name;

#define http_host_len 256

interface IHttpProc : public IBase
{
    std_method(OnHttpAuth)(ULONG event) PURE;
    std_method(OnHttpNotify)(crtid event, crterr err) PURE;
    std_method(OnHttpSendParam)(UCHAR* key, buf_len klen, UCHAR* value, buf_len vlen) PURE;
    std_method(OnHttpRecvParam)(UCHAR* key, buf_len klen, UCHAR* value, buf_len vlen) PURE;
    std_method(OnHttpSendHeaded)(UCHAR* data, buf_len size) PURE;
    std_method(OnHttpRecvHeaded)(UCHAR* data, buf_len size) PURE;
    std_method(OnHttpSendBody)(UCHAR* data, buf_len size) PURE;
    std_method(OnHttpRecvBody)(UCHAR* data, buf_len size) PURE;
};

// {8C102441-E383-4B3C-8CC8-7C8E0B0162FE}
_DEF_IID(IID_IHttpProc, 0x8c102441, 0xe383, 0x4b3c, 0x8c, 0xc8, 0x7c, 0x8e, 0xb, 0x1, 0x62, 0xfe);

interface IHttp : public IBase
{
    std_method(BindEvent)(IBase* pBase) PURE;
    std_method(UnBindEvent)() PURE;
    std_method(SetCookies)(http_header* data) PURE;
    std_method(Open)(SafeStringPtr addr, SafeStringPtr scheme, unsigned short port) PURE;
    std_method(ReSet)() PURE;
    std_method(Cancel)() PURE;
    std_method_(int, IsComplete)() PURE;
};

// {6014F5E1-05A9-476F-898C-8606756A750F}
_DEF_IID(IID_IHttp, 0x6014f5e1, 0x5a9, 0x476f, 0x89, 0x8c, 0x86, 0x6, 0x75, 0x6a, 0x75, 0xf);

interface IHttpSrvProc : public IBase
{
    std_method(OnAccept)(crterr err, LPCSTR hostname, LPCSTR host) PURE;
};

// {23C86623-C039-416B-A489-C175C360E692}
_DEF_IID(IID_IHttpSrvProc, 0x23c86623, 0xc039, 0x416b, 0xa4, 0x89, 0xc1, 0x75, 0xc3, 0x60, 0xe6, 0x92);

interface IHttpSrv : public IBase
{
};

// {75BD9CAF-2D0D-4408-B481-655F30F8613F}
_DEF_IID(IHttpSrv, 0x75bd9caf, 0x2d0d, 0x4408, 0xb4, 0x81, 0x65, 0x5f, 0x30, 0xf8, 0x61, 0x3f);

#endif
